<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :edit="edit" :checkedit="checkedit" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {
		buildSubFormData,
		subOnLoad,
		changeEditor,
		configSelectData
	} from '../../../static/js/formUtil.js';
	import {
		ignoreHtml,
		ptFloat,
		minusF,
		getDateStr,
		errorModal 
	} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				assetIdCache:"asset-deviceStocktaking-data-info-assetId-cache",
				inventoryTakerIdCache:"asset-deviceStocktaking-data-info-inventoryTakerId-cache",
				inventoryTakerId:'',
				inventoryTakerName:'',
			})
		},
		methods:{
			initload(){
				let _that = this
				let pro1 = _that.om.request("dictZero/getListByCode",{code:'40444'})
				Promise.all([pro1]).then(res=>{
					_that.$refs.autoform.changeEditor('dataStr', 'inventoryReportId', 'data', configSelectData(res[0], 'code','dicname'))
					_that.$refs.autoform.initSelectIndex('dataStr', 'inventoryReportId')
				})
			},
			clearAssetId(){
				let _that = this
				_that.$refs.autoform.clear('dataStr', 'assetId');
				_that.$refs.autoform.clear('dataStr', 'assetTypeId');
				_that.$refs.autoform.clear('dataStr', 'assetName');
				_that.$refs.autoform.clear('dataStr', 'model');
				_that.$refs.autoform.clear('dataStr', 'location');
				_that.$refs.autoform.clear('dataStr', 'useSituationId');
				_that.$refs.autoform.clear('dataStr', 'operatingStatusId');
				_that.$refs.autoform.clear('dataStr', 'userId');
				_that.$refs.autoform.clear('dataStr', 'userPositionId');
				_that.$refs.autoform.clear('dataStr', 'userDepartmentId');
				_that.$refs.autoform.clear('dataStr', 'managerId');
				_that.$refs.autoform.clear('dataStr', 'managementPositionId');
				_that.$refs.autoform.clear('dataStr', 'managementDepartmentId');
				_that.$refs.autoform.clear('dataStr', 'assetLendingId');
				_that.$refs.autoform.clear('dataStr', 'issuanceDate');
				_that.$refs.autoform.clear('dataStr', 'stakeholderTypesId');
				_that.$refs.autoform.clear('dataStr', 'stakeholderId');
				_that.$refs.autoform.clear('dataStr', 'remark');
			},
		},
		onLoad(e) {
			let _that = this
			_that.inventoryTakerId = e.inventoryTakerId
			_that.inventoryTakerName = e.inventoryTakerName
			_that.subIndex = (Number(e.index)+1)
			subOnLoad(_that, e, function() {
				if (e.configDataCacheKey) {
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if (res.data && res.data instanceof Array) {
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
							}
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							

							changeEditor(_that.autoformdata[0].editors,"assetId",{
								"link":'../../public/pageSearch/pageSearch',
								"linkParam":{
									other:JSON.stringify({
										firstId:''
									}),
									url:'propertyWholeProjectLedgerShow/getPage',
									namefield:"assetCode",
									notefield:"assetName",
									extrafield:"assetCategoryName",
									searchfield:'q',
									initload:true,
									cachename:_that.assetIdCache
								}
							})
							changeEditor(_that.autoformdata[0].editors,"inventoryTakerId",{
								"link":'../../public/searchUser/searchUser',
								"linkParam":{
									other:JSON.stringify({
									}),
									isSingle:true,
									isUserPos:true,
									cachename:_that.inventoryTakerIdCache
								}
							})
							
							
							_that.$nextTick(function(){
								_that.initload()
							})
						}
					})
				}
			})
		},
		onShow() {
			let _that = this
			if (_that.$refs.autoform) {
				uni.getStorage({
					key: _that.assetIdCache,
					success: function(res) {
						if (res.data) {
							let d = res.data;
							var formdata = _that.$refs.autoform.formdata;
							formdata.assetId = d.id
							formdata.assetCode = d.assetCode
							formdata.assetTypeId = d.assetTypeId
							formdata.assetTypeName = d.assetTypeName
							formdata.assetName = d.assetName
							formdata.model = d.assetStd
							formdata.location = d.location
							formdata.useSituationId = d.useSituationId
							formdata.useSituationName = d.useSituationName
							formdata.operatingStatusId = d.operatingStatusId
							formdata.operatingStatusName = d.operatingStatusName
							formdata.userId = d.userId
							formdata.userName = d.userName
							formdata.userPositionId = d.userPositionId
							formdata.userPositionName = d.userPositionName
							formdata.userDepartmentId = d.userDepartmentId
							formdata.userDepartmentName = d.userDepartmentName
							formdata.managerId = d.managerId
							formdata.managerName = d.managerName
							formdata.managementPositionId = d.managementPositionId
							formdata.managementPositionName = d.managementPositionName
							formdata.managementDepartmentId = d.managementDepartmentId
							formdata.managementDepartmentName = d.managementDepartmentName
							formdata.assetLendingId = d.assetLendingId
							formdata.assetLendingName = d.assetLendingName
							formdata.issuanceDate = d.issuanceDate
							formdata.stakeholderTypesId = d.stakeholderTypesId
							formdata.stakeholderTypesName = d.stakeholderTypesName
							formdata.stakeholderId = d.relatedPartiesId
							formdata.stakeholderName = d.relatedPartiesName
							formdata.remark = d.remark
							uni.removeStorage({
								key: _that.assetIdCache
							});
						}
					}
				});
				uni.getStorage({
					key:_that.inventoryTakerIdCache,
					success:(res)=>{
						if(res.data){
							let d = res.data[0]
							let formdata = _that.$refs.autoform.formdata
							formdata.inventoryTakerId = d.id
							formdata.inventoryTakerName = d.username
							uni.removeStorage({
								key:_that.inventoryTakerIdCache
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>
